package com.zzj.controller;

import com.github.pagehelper.PageInfo;
import com.zzj.bean.ProductBean;
import com.zzj.service.ProductService;
import com.zzj.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api
//@CrossOrigin
@RequestMapping("product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("findAll")
    @ApiOperation("查询所有订单详情")
    public PageInfo<ProductBean> findAll(
            @RequestParam(defaultValue = "1")int pageNum,
            @RequestParam(defaultValue = "5")int pageSize,
            String ooid
    ){
        return productService.getProductByOoid(pageNum,pageSize,ooid);
    }

    @PostMapping("add")
    @ApiOperation("添加订单详情")
    public Result addProduct(@RequestBody List<ProductBean> productBeans){
        System.out.println("productBeans = " + productBeans);
        for (ProductBean productBean : productBeans) {
            System.out.println(productBean.getPcount());
        }
        return productService.addProduct(productBeans);
    }

    @ApiOperation("质检员可以看到的产品")
    @GetMapping("findAllProduct")
    public PageInfo<ProductBean> findAllProduct(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize){
        return productService.findAll(pageNum,pageSize);
    }

    @GetMapping("findProductByState")
    public PageInfo<ProductBean> findAllQualityByState(
            @RequestParam(defaultValue = "1")int pageNum,
            @RequestParam(defaultValue = "5")int pageSize,
            String pstate){
        return productService.findAllQualityByState(pageNum,pageSize,pstate);
    }
}
